package com.example.myapplication4_3;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        EditText edt1 = findViewById(R.id.edt1);
        EditText edt2 = findViewById(R.id.edt2);
        TextView txt1 = findViewById(R.id.textView3);
        Button btn1 = findViewById(R.id.button);

        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String name = edt1.getText().toString();
                String psw = edt2.getText().toString();

                if("王炜明".equals(name) && "2306010131".equals(psw))
                {
                    txt1.setText("登录成功！");
                    txt1.setTextColor(Color.RED);
                }
                else
                {
                    txt1.setText("用户名或密码错误！");
                    txt1.setTextColor(Color.RED);
                    edt1.setText("");
                    edt2.setText("");
                }
            }
        });
    }
}